package com.krediti.session;

import java.util.ArrayList;
import java.util.List;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

import com.krediti.entity.KreditniZahtev;
import com.krediti.entity.Status;

@Name("statusHome")
public class StatusHome extends EntityHome<Status> {

	/**
	 * Generated serial version.
	 */
	private static final long serialVersionUID = 5640836722451343129L;

	public void setStatusId(Integer id) {

		setId(id);
	}

	public Integer getStatusId() {
		return (Integer) getId();
	}

	@Override
	protected Status createInstance() {
		Status status = new Status();
		return status;
	}

	public void wire() {
		getInstance();
	}

	public boolean isWired() {
		return true;
	}

	public Status getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<KreditniZahtev> getKreditniZahtev() {
		return getInstance() == null ? null : new ArrayList<KreditniZahtev>(
				getInstance().getKreditniZahtev());
	}

	/**
	 * 
	 * Returns initial status. All loan requests are initial on that status.
	 * 
	 * @return Status
	 */
	public Status findInitialStatus() {

		Status status = (Status) getEntityManager().createQuery(
				"from Status where id = :id").setParameter("id", 1)
				.getSingleResult();
		return status;
	}

	/**
	 * TODO Returns status confirmed.
	 * 
	 * @return Status
	 */
	public Status findStatus(String nazivStatusa) {

		Status status = (Status) getEntityManager().createQuery(
				"from Status where naziv = :naziv").setParameter("naziv",
				nazivStatusa).getSingleResult();
		return status;
	}

}
